package com.example.function.sys.model.pojo;


import com.example.common.support.ApplicationContextProvider;
import com.example.function.sys.model.one.SysDepartment;
import com.example.function.sys.model.one.SysUser;
import com.example.function.sys.service.ISysDepartmentService;
import com.example.function.sys.service.ISysUserService;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: <SysDepartmentPojo vo>. <br>
 * <p>
 * generate time:2021-7-22 10:43:22
 *
 * @author hanqf
 * @version V1.0
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class SysDepartmentUsersPojo extends SysDepartmentPojo {
    private static final long serialVersionUID = 1L;


    /*
    部门用户列表
     */
    List<SysUserMiniPojo> users;


    /**
     * 实体对象复制到数据对象
     */
    public static SysDepartmentUsersPojo wrapper(SysDepartment sysDepartment) {
        SysDepartmentUsersPojo sysDepartmentUsersPojo = new SysDepartmentUsersPojo();
        BeanUtils.copyProperties(sysDepartment, sysDepartmentUsersPojo);
        final ISysDepartmentService sysDepartmentService = (ISysDepartmentService) ApplicationContextProvider.getBean("sysDepartmentService");

        final ISysUserService sysUserService = (ISysUserService) ApplicationContextProvider.getBean("sysUserService");
        //封装部门用户列表
        List<SysUserMiniPojo> userDepartPojos = new ArrayList<>();
        final List<SysUser> usersList = sysUserService.findUsersByDepartmentId(sysDepartment.getId());
        for (SysUser sysUser : usersList) {
            userDepartPojos.add(SysUserMiniPojo.wrapper(sysUser));
        }
        sysDepartmentUsersPojo.setUsers(userDepartPojos);

        return sysDepartmentUsersPojo;
    }

}



